#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<map>

using namespace std;

typedef struct BTNode
{
	char data;
	struct BTNode *lchild,*rchild;
}tBTNode;


tBTNode * build_tree_by_pre_in_order(char *pre,char *in,int len)
{
	if(len<=0)
	{
		return NULL;
	}
	
	int i = 0;
	for(;in[i]!=pre[0];i++);
	
	tBTNode *p = new tBTNode();
	p->data = pre[0];

	p->lchild = build_tree_by_pre_in_order(pre+1,in,i);

	p->rchild = build_tree_by_pre_in_order(pre+i+1,in+i+1,len-i-1);

	return p;
}

void traverse(tBTNode *p)
{
	if(p==NULL)
	{
		return ;
	}

	traverse(p->lchild);
	traverse(p->rchild);
	cout<<p->data;
}


int main()
{
	char pre_order[30];
	char in_order[30];

	while(cin>>pre_order>>in_order)
	{
		tBTNode *p = build_tree_by_pre_in_order( pre_order,in_order,strlen(pre_order) );
		traverse(p);
		cout<<endl;
	}

	return 0;
}
